<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="/WEB-INF/jsp/include/easyui.jsp" %>
<%@ include file="/WEB-INF/jsp/include/pGrid.jsp" %>
<title>模块列表模板</title>
<script>
	function inputSearchFormat (row){
		var input = "",inputName = row.field +"_searchType";
		switch(row.searchType){
			case 'like':input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"like\" />";break;
			case 'eq': 	input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"eq\" />"; 	break;
			case 'neq': input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"neq\" />"; break;
			case 'gt':  input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"gt\" />"; 	break;
			case 'ge':  input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"ge\" />"; 	break;
			case 'lt':  input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"lt\" />"; 	break;
			case 'le':  input = "<input type=\"hidden\" name=\""+ inputName +"\" value=\"le\" />"; 	break;
			default:break;
		}
		return input;
	} 
	
	function inputFormat (row){
		var input = "";
		var required = (row.required=='Y'?true:false) ;
		switch(row.type){
			case 'text':
				input = "  <input class=\"easyui-textbox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +"\" />";
				break;
			case 'textarea':
				input = "  <input class=\"easyui-textbox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +",multiline:true\" />";
				break;
			case 'combobox':
				input = "  <select class=\"easyui-combobox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +"\" ><option value=\"\">--请选择--</option></select>";
				break;
			case 'comboboxM':
				input = "  <select class=\"easyui-combobox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +"\" multiple=\"multiple\"><option value=\"\">--请选择--</option></select>";
				break;
			case 'combotree':
				input = "  <select class=\"easyui-combotree\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +"\" ><option value=\"\">--请选择--</option></select>";
				break;
			case 'numberbox':
				input = "  <input class=\"easyui-numberbox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +",min:0\" />";
				break;
			case 'datebox':
				input = "  <input class=\"easyui-datebox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +"\" />";
				break;
			case 'datetimebox':
				input = "  <input class=\"easyui-datetimebox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"label:'"+ row.title +":',required:"+ required +"\" />";
				break;
			case 'filebox':
				input = "  <input class=\"easyui-filebox\" name=\""+ row.field +"\" style=\"width:240px;\" data-options=\"prompt:'Choose a file...',label:'"+ row.title +":',required:"+ required +"\" />";
				break;
			default:break;
		}
		return input;
	}
	/*自动动态创建表格*/
	function autoCreateGridJson(gridJson){
		var formFlag = true;
		var grid = {};
		var columns = [];
		var queryForm = [];
		queryForm.push("<form id=\"queryForm\" >");
		queryForm.push(" <input type=\"hidden\" name=\"className\" value=\"${className}\" />");
		var data = gridJson;
		$.each(data.rows,function(index,row){
			if(row.inlist=='Y'){
				columns.push({ field:row.field,width:row.width,title:row.title });
			} 
			if(row.insearch=='Y'){
				formFlag = false;
				queryForm.push(" <div class=\"formItem\" style=\"margin-top:5px;margin-left:10px;float:left;\">");
				queryForm.push(inputFormat(row));
				queryForm.push(inputSearchFormat(row));
				queryForm.push(" </div>");
			}
		});
		if(formFlag){
			var fieldHtml =  '<div style="margin-top:5px;margin-left:10px;float:left;">' + 
		  	'<input class="easyui-textbox" name="fieldName" style="width:240px;" data-options="label:\'虚位以待:\',required:false" />'+ 
			'<input type="hidden" name="fieldName_searchType" value="like" />' 
		 	'</div>';
			queryForm.push(fieldHtml);
		}
		queryForm.push("</form>");
		grid.gridParam = {
			columns:[columns] ,
			"url": "/console/${className}/list" 
		};
		grid.queryForm = queryForm.join("\r\n");
		return grid ;
	}

	$(function(){ 
		var gridJson = '${gridJson}' ;
	 	gridJson = JSON.parse(gridJson);
	 	
	 	gridJson =  autoCreateGridJson(gridJson);
		var gridParam = gridJson.gridParam;
		
		$("#queryForm").parent().html(gridJson.queryForm);
		
		$.parser.parse('#queryForm'); 

		/*数据列表初始化模块*/
		p.dataGrid = $(p.dataGrid).datagrid($.extend({},p.dataGridParam,gridParam,{
		}));
		
		/*toolbar按钮点击事件响应*/
		$(".easyui-linkbutton").on("click",function(){
			var id = $(this).attr("id");
			switch(id){
				case "b_1": break;
				case "b_N": break;
				default:break;
			}
		});
	});
</script>
</head>
<body class="easyui-layout">
	<!-- 但行高度33px，多行时 33乘以行数  -->
	<div data-options="region:'north',split:false,border:false" style="height:33px;">
		<div class="easyui-panel" data-options="fit:true,border:false"  >
			<!-- 查询条件表单，根据配置进行替换  -->
			<form id="queryForm">
				 <input type="hidden" name="className" value="${className}" />
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="fieldName" style="width:240px;" data-options="label:'虚位以待:',required:false" />
					<input type="hidden" name="fieldName_searchType" value="like" />
				 </div>
			</form>		
		</div>
	</div>  

	<!-- 工具栏 -->
	<div id="toolbar" class="easyui-panel" style="padding:3px;">
		<!-- 工具栏搜索表单 -->
		<!-- 工具栏按钮 -->
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="b_1">新增</a>
      	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="b_2">编辑</a>
     	<a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" id="b_3">删除</a>
      	<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="b_4">查询</a>
	</div>
	
	<!-- 表格 -->
	<div region="center" border="false">
		<table id="dataGrid"></table>
	</div>
</body>
</html>